<template>
  <div>
    <Modal width="1200"  footer-hide v-model="apiLogDetailShow" title="日志记录详情" >
      <div class="report-content">
        <Form ref="formItem" :model="apiLog" :label-width="140" label-position="left">
          <Row class="base-form" >
            <p>基本信息</p>
            <FormItem prop="id" label="id：">
              {{ apiLog.id }}
            </FormItem>
            <FormItem prop="url" label="请求地址：">
              {{ apiLog.url }}
            </FormItem>
            <FormItem prop="createTime" label="请求时间：">
              {{ apiLog.createTime }}
            </FormItem>
            <FormItem prop="requestContent" label="请求内容：">
              {{ apiLog.requestContent }}
            </FormItem>
            <FormItem prop="responseContent" label="返回内容：">
              <Button type="error" size="small" @click="sendAgain(apiLog)">重新推送</Button>
              {{ apiLog.responseContent }}
            </FormItem>
            <FormItem prop="responseContent" label="重发返回值：" style="background-color: #F8F8F8; color: red;">
              {{ sendAgainMsg }}
            </FormItem>
            <FormItem prop="otherRelationId" label="业务Id：">
              {{ apiLog.otherRelationId }}
            </FormItem>
            <FormItem prop="businessType" label="业务类型：">
              {{ apiLog.businessType }}
            </FormItem>
            <FormItem prop="requestType" label="请求类型：">
              {{ apiLog.requestType }}
            </FormItem>
            <FormItem prop="companyId" label="渠道公司：">
              {{ apiLog.companyId }}
            </FormItem>
            <FormItem prop="otherCompanyId" label="V10公司Uuid：">
              {{ apiLog.otherCompanyId }}
            </FormItem>
            <FormItem prop="premisesId" label="楼盘Id：">
              {{ apiLog.premisesId }}
            </FormItem>
            <FormItem prop="premisesName" label="楼盘名称：">
              {{ apiLog.premisesName }}
            </FormItem>
            <FormItem prop="partnerId" label="经纪人Id：">
              {{ apiLog.partnerId }}
            </FormItem>
            <FormItem prop="partnerName" label="经纪人姓名：">
              {{ apiLog.partnerName }}
            </FormItem>
            <FormItem prop="businessTime" label="业务创建时间：">
              {{ apiLog.businessTime }}
            </FormItem>
            <FormItem prop="agentCompanyId" label="经纪公司Id：">
              {{ apiLog.agentCompanyId }}
            </FormItem>
            <FormItem prop="reamrk" label="备注：">
              {{ apiLog.reamrk }}
            </FormItem>
          </Row>
        </Form>
      </div>
    </Modal>
  </div>
</template>

<script>
import { formatTime } from '@/utils'
import Api from '@/api'

const systemApiLogApi = Api.SystemApiLog
export default {
  name: 'apiLogDetailModal',
  data() {
    return {
      apiLogDetailShow: false,
      apiLog: {

      },
      sendAgainMsg: ''
    }
  },
  methods: {
    initData(apiLogInfo) {
      this.apiLog = apiLogInfo;
      this.apiLogDetailShow = true;
    },
    cleanParams() {
      this.apiLog = {};
      this.sendAgainMsg = '';
    },
    sendAgain(obj) {
      const url = obj.url;
      const responseContent = obj.responseContent;
      if (url.indexOf('channel-openapi') >= 0) {
        // V10请求渠道,无需补发
        this.$Message.success('V10请求渠道接口,无补发功能！');
      } else if (url.indexOf('http://open-api') >= 0) {
        // 渠道请求V10接口
        const status = obj.status;
        if (status === 'success') {
          this.$Message.success('接口成功,无需补发！');
        } else {
          if (!obj.requestContent) {
            this.$Message.success('无请求内容,无需补发！');
            return;
          }
          this.$Modal.confirm({
            title: '补发V10请求',
            content: '原始错误内容: ' + responseContent,
            onOk: () => {
              this.sendApiLogAgain(obj.id)
            }
          })
        }
      }
    },
    async sendApiLogAgain(id) {
      const { responseCode, responseMessage, responseType } = await this.$request(systemApiLogApi.sendApiLogAgain, { id })
      this.$Message.success(responseMessage);
      this.sendAgainMsg = responseMessage;
    },
  }
}
</script>

<style scoped>
  .report-f1{margin: 10px 0;}
  .report-f2{margin: 10px 0;}
  .report-f3{margin: 10px 0;}
  .report-content{height: 750px;overflow-y:scroll}
  .aaa {
    color: #f8f6f6
  }
</style>
